
package cn.xy.third.sms.email;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.Map;

/**
 * 邮件模板
 *
 *  
 */
@Data
public class EmailTemplate implements Serializable {

    /**
     * 模板
     */
    private String templateContent;

    /**
     * 标题
     */
    private String templateTitle;

    /**
     * 模板名
     */
    private String templateName;

    public String toBody(Map<String, String> templateParam) {
        if (CollUtil.isEmpty(templateParam) || CharSequenceUtil.isEmpty(this.templateContent)) {
            return "";
        }
        String body = this.templateContent;
        for (Map.Entry<String, String> entry : templateParam.entrySet()) {
            body = body.replace("${" + entry.getKey() + "}", entry.getValue());
        }
        return body;
    }
}
